<?php

use yii\db\Migration;

class m000005_000001_create_card_basic extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%card_basic}}', [
            'id' => $this->primaryKey(),
            'card_id' => $this->integer()->notNull()->comment('卡编号'),
            'refresh_time' => $this->integer()->notNull()->comment('刷新时间'),
            'iccid' => $this->string(32)->comment('ICCID'),
            'terminal_id' => $this->string(32)->comment('terminalId'),
            'modem_id' => $this->string(32)->comment('modemId'),
            'customer' => $this->string(32)->comment('customer'),
            'end_consumer_id' => $this->string(32)->comment('endConsumerId'),
            'suspended' => $this->string(1)->comment('suspended'),
            'rate_plan' => $this->string(128)->comment('ratePlan'),
            'status' => $this->string(32)->comment('ratePlan'),
            'month_to_date_usage' => $this->decimal(20, 4)->comment('monthToDateUsage'),
            'overage_limit_reached' => $this->integer()->comment('overageLimitReached'),
            'overage_limit_override' => $this->string(32)->comment('overageLimitOverride'),
            'date_activated' => $this->integer()->comment('dateActivated'),
            'date_added' => $this->integer()->comment('dateAdded'),
            'date_modified' => $this->integer()->comment('dateModified'),
            'date_shipped' => $this->integer()->comment('dateShipped'),
            'month_to_date_data_usage' => $this->decimal(20, 4)->comment('monthToDateDataUsage'),
            'month_to_date_sms_usage' => $this->decimal(20, 4)->comment('monthToDateSMSUsage'),
            'month_to_date_voice_usage' => $this->decimal(20, 4)->comment('monthToDateVoiceUsage'),
            'secure_sim_id' => $this->string(32)->comment('secureSimId'),
            'custom1' => $this->string(32)->comment('custom1'),
            'custom2' => $this->string(32)->comment('custom2'),
            'custom3' => $this->string(32)->comment('custom3'),
            'rating_term_start_date' => $this->integer()->comment('rating.termStartDate'),
            'rating_term_end_date' => $this->integer()->comment('rating.termEndDate'),
            'rating_renewal_policy' => $this->string(32)->comment('rating.renewalPolicy'),
            'rating_renewal_rate_plan' => $this->string(32)->comment('rating.renewalRatePlan'),
            'rating_total_primary_included_data' => $this->decimal(20, 4)->comment('rating.totalPrimaryIncludedData'),
            'rating_primary_data_remaining' => $this->decimal(20, 4)->comment('rating.primaryDataRemaining'),
            'rating_total_primary_included_sms' => $this->decimal(20, 4)->comment('rating.totalPrimaryIncludedSMS'),
            'rating_primary_sms_remaining' => $this->decimal(20, 4)->comment('rating.primarySMSRemaining'),
            'secure_sim_username_copy_rule' => $this->string(1)->comment('secureSimUsernameCopyRule'),
            'secure_sim_password_copy_rule' => $this->string(1)->comment('secureSimPasswordCopyRule'),
            'account_id' => $this->integer()->comment('accountId'),
            'fixed_ip_address' => $this->string(32)->comment('fixedIpAddress'),
            'ctd_session_count' => $this->integer(32)->comment('ctdSessionCount'),
            'customer_custom1' => $this->string(32)->comment('customerCustom1'),
            'customer_custom2' => $this->string(32)->comment('customerCustom2'),
            'customer_custom3' => $this->string(32)->comment('customerCustom3'),
            'customer_custom4' => $this->string(32)->comment('customerCustom4'),
            'customer_custom5' => $this->string(32)->comment('customerCustom5'),
            'operator_custom1' => $this->string(32)->comment('operatorCustom1'),
            'operator_custom2' => $this->string(32)->comment('operatorCustom2'),
            'operator_custom3' => $this->string(32)->comment('operatorCustom3'),
            'operator_custom4' => $this->string(32)->comment('operatorCustom4'),
            'operator_custom5' => $this->string(32)->comment('operatorCustom5'),
            'imsi' => $this->string(32)->comment('imsi'),
            'primary_iccid' => $this->string(32)->comment('primaryICCID'),
            'imei' => $this->string(32)->comment('imei'),
            'global_sim_type' => $this->string(32)->comment('globalSimType'),
            'sim_notes' => $this->string(128)->comment('simNotes'),
            'version' => $this->integer()->comment('version'),
            'custom4' => $this->string(32)->comment('custom4'),
            'custom5' => $this->string(32)->comment('custom5'),
            'custom6' => $this->string(32)->comment('custom6'),
            'custom7' => $this->string(32)->comment('custom7'),
            'custom8' => $this->string(32)->comment('custom8'),
            'custom9' => $this->string(32)->comment('custom9'),
            'custom10' => $this->string(32)->comment('custom10'),
            'msisdn' => $this->string(32)->comment('msisdn'),
        ]);
        $this->createIndex('fk_card_basic_card1_idx', '{{%card_basic}}', ['card_id']);
        try {
            $this->addForeignKey('fk_card_basic_card1', '{{%card_basic}}', ['card_id'], '{{%card}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
    }

    public function down()
    {
        $this->dropTable('{{%card_basic}}');
    }
}
